package com.freshfresh.utils;

import java.util.UUID;


import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;

public class DeviceUtil {
	/**
	 * 自定义UUID。包括设备号，序列号，SIM卡串号等
	 * 
	 * @author tang.gw
	 */
	public static String getMyUUID(Activity ac) {
		String tmDevice;
		String tmSerial;
		// SIM号码
		String tmPhone;
		// SIM卡串号
		String IMSI;
		String androidId;
		String deviceSoftwareVersion;

		TelephonyManager tm = (TelephonyManager) ac.getBaseContext()
				.getSystemService(Context.TELEPHONY_SERVICE);

		tmDevice = "" + tm.getDeviceId();
		tmSerial = "" + tm.getSimSerialNumber();
		tmPhone = "" + tm.getLine1Number();
		IMSI = "" + tm.getSubscriberId();
		androidId = ""
				+ android.provider.Settings.Secure.getString(
						ac.getContentResolver(),
						android.provider.Settings.Secure.ANDROID_ID);
		deviceSoftwareVersion = "" + tm.getDeviceSoftwareVersion();

		UUID deviceUuid = new UUID(androidId.hashCode(),
				((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()
						| tmPhone.hashCode() | IMSI.hashCode()
						| deviceSoftwareVersion.hashCode());

		String uniqueId = deviceUuid.toString();
		// MyLogPrinter.print("before tmDevice:"+tmDevice+"/tmSerial:"+tmSerial+"/tmPhone:"+tmPhone+"/IMSI:"+IMSI+"/androidId:"+androidId+"/deviceSoftwareVersion:"+deviceSoftwareVersion+"");

		return uniqueId;
	}
}
